<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuimini/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">
        <form id="userForm">
            <div class="layui-form layuimini-form" lay-filter="add_ncc">

                <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                  <legend class="layui-font-green">邮箱配置</legend>
                </fieldset>

                <div class="layui-form-item">
                    <label class="layui-form-label required">邮件服务器</label>
                    <div class="layui-input-block">
                        <input type="text" name="host" id="host" lay-verify="required" lay-reqtext="邮件服务器名称不能为空" placeholder="请输入邮件服务器名称" value="{{objs.host}}" class="layui-input">
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label required">邮箱账号</label>
                    <div class="layui-input-block">
                        <input type="text" name="email" id="email" lay-verify="required" lay-reqtext="邮箱账号不能为空" placeholder="请输入邮箱账号" value="{{objs.email}}" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label required">密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="password" id="password" autocomplete="off" lay-verify="required" lay-reqtext="密码不能为空" placeholder="请输入密码" value="{{objs.password}}" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label required">端口</label>
                    <div class="layui-input-block">
                        <input type="text" name="port" id="port" lay-verify="required" lay-reqtext="端口不能为空" placeholder="请输入端口" value="{{objs.port}}" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label required">发件人昵称</label>
                    <div class="layui-input-block">
                        <input type="text" name="cname" id="cname"  value="{{objs.cname}}" lay-verify="required" lay-reqtext="发件人昵称不能为空" placeholder="请输入发件人昵称"  class="layui-input">
                    </div>
                </div>


                <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                  <legend class="layui-font-green">API配置</legend>
                </fieldset>

                <div class="layui-form-item">
                    <label class="layui-form-label">API</label>
                    <div class="layui-input-block">
                        <input type="text" name="apitoken" id="apitoken"  value="{{objs.apitoken|default:''}}" lay-reqtext="编码不能为空" placeholder="请输入编码"  class="layui-input">
                    </div>
                </div>


                <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                  <legend class="layui-font-green">自愈沉默区间</legend>
                </fieldset>
                <div class="layui-form-item">
                    <label class="layui-form-label">沉默开关</label>
                    <div class="layui-input-block">
                        {% if objs.switch_silence == 'on' %}
                        <input type="checkbox" name="switch_silence"  checked lay-skin="switch" lay-filter="switchSilence"  lay-text="开启|关闭">
                        {% else %}
                        <input type="checkbox" name="switch_silence"  lay-skin="switch" lay-filter="switchSilence"  lay-text="开启|关闭">
                        {% endif %}
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">开始时间</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" id="s_time" name="s_time" type="text" value="{{objs.s_time}}" placeholder="H:M:S">
                    </div>
                    <label class="layui-form-label">结束时间</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" id="e_time" name="e_time" type="text" value="{{objs.e_time}}" placeholder="H:M:S">
                    </div>
                </div>


                <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                  <legend class="layui-font-green">自愈时效性</legend>
                </fieldset>
                <div class="layui-form-item">
                    <label class="layui-form-label">自愈时效性</label>
                    <div class="layui-input-block">
                      <select name="valid" lay-verify="required">
                        {% if objs.valid == '1' %}
                            <option value="1" selected>1分钟</option>
                            <option value="2" >2分钟</option>
                            <option value="3">5分钟</option>
                        {% elif objs.valid == '2'  %}
                            <option value="1" >1分钟</option>
                            <option value="2" selected>2分钟</option>
                            <option value="3">5分钟</option>
                        {% else %}
                            <option value="1" >1分钟</option>
                            <option value="2" >2分钟</option>
                            <option value="5" selected>5分钟</option>
                        {% endif %}



                      </select>
                    </div>
                </div>

                <div class="layui-form-item" style="text-align: center">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="attention">立即提交</button>
                </div>
            </div>

            </div>


        </form>

    <script src="/static/layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    </div>

</div>

<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;
        window.$ = layui.$;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        //初始化选择时间控件
         var myDate = new Date();//获取当前时间设置选择时间的范围
        var maxtime = myDate.getFullYear() + "-" + (myDate.getMonth() + 1) + "-" + (myDate.getDate());//拼接当前是时间

        laydate.render({
            elem: '#s_time'
            ,type: 'time'
          });

        laydate.render({
            elem: '#e_time'
            ,type: 'time'
          });

        form.render();
        
        //监听提交
        form.on('submit(attention)', function (data) {
            //debugger;
            //alert(JSON.stringify(data.field));
            layer.alert(data.field.valid);
            $.ajax({
                url: '/alert/attentionconfig/',
                type: 'POST',
                data: data.field,
                success: function (res) {
                    layer.alert(res.msg);
                    location.reload();
                }
            })


        });
    });
</script>

</body>
</html>